﻿#ifndef JBARCHART_H
#define JBARCHART_H

#include <QWidget>
#include <QPaintEvent>
#include <QPropertyAnimation>

#define BAR_OUT_MARGIN          100             // 柱状图外部边距
#define TICK_LENGTH             5               // 刻度的长度
#define BAR_FONTSIZE_FACTOR     45

class JBarChart : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(int _height READ _getValue WRITE _setValue)

public:
    explicit JBarChart(QWidget *parent = nullptr);

private:
    void                initDefaultColorList();
    void                initAnimation();

    void                drawBar(QPainter *painter);

    void                _setValue(int height);
    int                 _getValue();

protected:
    void                paintEvent(QPaintEvent *event);
    void                resizeEvent(QResizeEvent *event);

    // 外部接口
public:
    void                setAnimation(bool useAnimation);
    void                setValue(QList<double> valueList, QStringList textList);
    void                setTextColor(QColor color);
    void                setBarColor(QColor color);
    void                setGridColor(QColor color);
    void                setMultiColor(bool useMultiColor);

signals:

private:
    QList<double>       _valueList;
    QStringList         _textList;
    QColor              _textColor;
    QColor              _barColor;
    QColor              _gridColor;
    QList<QColor>       _defaultColorList;

    bool                _useAnimation;
    QPropertyAnimation *_pAnimation;
    int                 _height;

    bool                _useMultiColor;
};

#endif // JBARCHART_H
